//
//  LJYMainController.swift
//  新浪微博
//
//  Created by 李俊扬 on 2017/6/29.
//  Copyright © 2017年 李俊扬. All rights reserved.
//

import UIKit

class LJYMainController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 自定义tabBar
        let tabBar = LJYTabBar()
        
        
        // 设置代理
        tabBar.ljyDelegate = self
        // 闭包实例化
        tabBar.closure = {
            
            print("监听按钮")
        }
        // 使用KVC完成只读属性
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(childController: LJYHomeController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(childController: LJYMessageController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(childController: LJYDisscoverController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(childController: LJYProfileController(), title: "我的", imgName: "tabbar_profile")
        
    }
    
    func addChildViewController(childController: UIViewController, title:String, imgName: String) {
        // 设置title
        childController.navigationItem.title = title
        childController.tabBarItem.title = title
        // 选中颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)
        // 设置image
        childController.tabBarItem.image = UIImage(named: imgName)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        // 高亮
        childController.tabBarItem.selectedImage  = UIImage(named: "\(imgName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        // 导航栏
        let nav = LJYNaigationController(rootViewController: childController)
        
        // 添加子控制器
        addChildViewController(nav)
    }
    
}

extension LJYMainController: LJYTabBarDelegate {
    
    func composeButtonSelect() {
        print("点击代理")
    }
}
